package org.forum.service.impl;

import java.io.Serializable;
import java.util.List;

import org.forum.dao.ForumDao;
import org.forum.dao.MainTopicDao;
import org.forum.domain.MainTopic;
import org.forum.service.HomeInfoService;
import org.forum.utils.JsonUtil;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;

public class HomeInfoServiceImpl implements HomeInfoService {

	private static Logger logger = LoggerFactory.getLogger(HomeInfoServiceImpl.class);

	private MainTopicDao mainTopicDao;

	private JsonUtil jsonUtil;

	/**
	 * 1、得到news相关的论坛 2、通过论坛返回论坛所有的main topic 3、按时间对所有main topic进行排序
	 * 4、将排完序的所有数据放入Struts容器
	 */

	@Override
	public List<MainTopic> getNewsInfo(int pageN_news, int pageSize_news, String sortBy) {
		List<MainTopic> mainTopics = mainTopicDao.getMainTopicsByClassification("news", pageN_news, pageSize_news,
				sortBy);
		return mainTopics;
	}

	@Override
	public List<MainTopic> getFinanceInfo(int pageN_finance, int pageSize_finance, String sortBy) {
		List<MainTopic> mainTopics = mainTopicDao.getMainTopicsByClassification("finance", pageN_finance,
				pageSize_finance, sortBy);
		return mainTopics;
	}

	@Override
	public List<MainTopic> getPEInfo(int pageN_PE, int pageSize_PE, String sortBy) {
		List<MainTopic> mainTopics = mainTopicDao.getMainTopicsByClassification("PE", pageN_PE, pageSize_PE, sortBy);
		return mainTopics;
	}

	@Override
	public List<MainTopic> getHistoryInfo(int pageN_history, int pageSize_history, String sortBy) {
		List<MainTopic> mainTopics = mainTopicDao.getMainTopicsByClassification("history", pageN_history, pageSize_history,
				sortBy);
		return mainTopics;
	}

	@Override
	public List<MainTopic> getPuzzleInfo(int pageN_puzzle, int pageSize_puzzle, String sortBy) {
		List<MainTopic> mainTopics = mainTopicDao.getMainTopicsByClassification("puzzle", pageN_puzzle, pageSize_puzzle,
				sortBy);
		return mainTopics;
	}

	@Override
	public void getMoreForum() {

	}

	@Override
	public List<MainTopic> getComprehensiveInfo(int pageN_comprehensive, int pageSize, String sortBy) {
		if(logger.isDebugEnabled()){
			logger.debug("getComprehensiveInfo is running!");
		}
		List<MainTopic> mainTopics = mainTopicDao.getMainTopicsDirectly(pageN_comprehensive, pageSize, sortBy);
		if(logger.isDebugEnabled()){
			logger.debug("mainTopics.size:"  + mainTopics.size());
		}
		return mainTopics;
	}

	public void setMainTopicDao(MainTopicDao mainTopicDao) {
		this.mainTopicDao = mainTopicDao;
	}

	public void setJsonUtil(JsonUtil jsonUtil) {
		this.jsonUtil = jsonUtil;
	}

}
